package com.binhthuan.catechist.client.form;

import com.binhthuan.catechist.client.ECApplication;
import com.binhthuan.catechist.client.ECUser;
import com.binhthuan.catechist.client.data.ScheduleDS;
import com.binhthuan.catechist.shared.constant.Parameter;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.FilterCriteriaFunction;
import com.smartgwt.client.widgets.form.fields.HiddenItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.form.fields.TextItem;

public class ScheduleForm extends AbstractForm {

    public ScheduleForm(ScheduleDS dataSource) {
        super(dataSource);
        setMargin(5);
        setNumCols(4);
        setCellPadding(5);

        HiddenItem idField = new HiddenItem(Parameter.ID);
        HiddenItem doctrineClassIdField = new HiddenItem(Parameter.COURSE);
        doctrineClassIdField.setValue(ECUser.getCurrentCourse());

        TextItem titleField = new TextItem(Parameter.TITLE);
        titleField.setTitle(ECApplication.getConstants().title());
        titleField.setRequired(true);
        titleField.setLength(20);
        titleField.setColSpan(4);
        titleField.setHint(ECApplication.getMessages().maximunNumberCharacters(20));
        
        SelectItem scheduleDayField = new SelectItem(Parameter.DATE);
        scheduleDayField.setTitle(ECApplication.getConstants().date());
        scheduleDayField.setPickListCriteria(new Criteria(Parameter.COURSE, ECUser.getCurrentCourse().toString()));
        scheduleDayField.setPickListFilterCriteriaFunction(new FilterCriteriaFunction() {
            
            @Override
            public Criteria getCriteria() {
                return new Criteria(Parameter.YEAR, ECUser.getSchoolYear().toString());
            }
        });

        SelectItem statusField = new SelectItem(Parameter.STATUS);
        statusField.setTitle(ECApplication.getConstants().status());

        TextAreaItem contentField = new TextAreaItem(Parameter.CONTENT);
        contentField.setTitle(ECApplication.getConstants().content());
        contentField.setRequired(true);
        contentField.setWidth(250);

        TextAreaItem commentField = new TextAreaItem(Parameter.COMMENT);
        commentField.setTitle(ECApplication.getConstants().comment());
        commentField.setWidth(250);

        ButtonItem saveButton = createSaveButton();
        saveButton.setColSpan(4);

        setFields(idField, doctrineClassIdField, titleField, scheduleDayField, statusField, contentField, commentField, saveButton);
    }
}
